﻿using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TruongViet.TVLib.Business;

public partial class BoSungBienMuc_DownloadFile :WebBase
{
    clsCommon objUpload; 
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
          txtthumucupload.Text = Request["Location"];
        }
    }
    protected void UpLoad()
    {
        FileInfo objFile;
        string strResult="";
        string strUpload = "";
        objUpload=new clsCommon();
        string strJs;
        string strduongdannghi = txtthumucupload.Text;
        
        if (FileUpload1.Value!= null && FileUpload1.Value!="")
        {
            objFile = new FileInfo(strduongdannghi +"\\"+FileUpload1.Value);
            if (chkOverwirte.Checked == false)
            {
                if (objFile.Exists == false)
                {
                    strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload1.Value);
                    if (strResult != "Fail")
                    {
                       cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload1.Value);
                        strUpload = strUpload+ strResult + ",";
                    }
                }
                else
                {
                    strJs = "alert('File này đã tồn tại');";
                    Page.RegisterClientScriptBlock("File4Js", "<script language='javascript'>" + strJs + "</script>");
                }
            }
            else
            {
                strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload1.Value);
                if (strResult != "Fail")
                {
                    cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload1.Value);
                    strUpload = strUpload + strResult + ",";
                }
            }
        }
        if (FileUpload2.Value != null && FileUpload2.Value != "")
        {
            objFile = new FileInfo(strduongdannghi + "\\" + FileUpload2.Value);
            if (chkOverwirte.Checked == false)
            {
                if (objFile.Exists == false)
                {
                    strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload2.Value);
                    if (strResult != "Fail")
                    {
                        cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload2.Value);
                        strUpload = strUpload + strResult + ",";
                    }
                }
                else
                {
                    strJs = "alert('File này đã tồn tại');";
                    Page.RegisterClientScriptBlock("File4Js", "<script language='javascript'>" + strJs + "</script>");
                }
            }
            else
            {
                strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload2.Value);
                if (strResult != "Fail")
                {
                    cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload2.Value);
                    strUpload = strUpload + strResult + ",";
                }
            }
        }

        if (FileUpload3.Value != null && FileUpload3.Value != "")
        {
            objFile = new FileInfo(strduongdannghi + "\\" + FileUpload3.Value);
            if (chkOverwirte.Checked == false)
            {
                if (objFile.Exists == false)
                {
                    strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload3.Value);
                    if (strResult != "Fail")
                    {
                        cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload3.Value);
                        strUpload = strUpload + strResult + ",";
                    }
                }
                else
                {
                    strJs = "alert('File này đã tồn tại');";
                    Page.RegisterClientScriptBlock("File4Js", "<script language='javascript'>" + strJs + "</script>");
                }
            }
            else
            {
                strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload3.Value);
                if (strResult != "Fail")
                {
                    cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload3.Value);
                    strUpload = strUpload + strResult + ",";
                }
            }
        }
        if (FileUpload4.Value != null && FileUpload4.Value != "")
        {
            objFile = new FileInfo(strduongdannghi + "\\" + FileUpload4.Value);
            if (chkOverwirte.Checked == false)
            {
                if (objFile.Exists == false)
                {
                    strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload4.Value);
                    if (strResult != "Fail")
                    {
                        cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload4.Value);
                        strUpload = strUpload + strResult + ",";
                    }
                }
                else
                {
                    strJs = "alert('File này đã tồn tại');";
                    Page.RegisterClientScriptBlock("File4Js", "<script language='javascript'>" + strJs + "</script>");
                }
            }
            else
            {
                strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload4.Value);
                if (strResult != "Fail")
                {
                    cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload4.Value);
                    strUpload = strUpload + strResult + ",";
                }
            }
        }
        if (FileUpload5.Value != null && FileUpload5.Value != "")
        {
            objFile = new FileInfo(strduongdannghi + "\\" + FileUpload5.Value);
            if (chkOverwirte.Checked == false)
            {
                if (objFile.Exists == false)
                {
                    strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload5.Value);
                    if (strResult != "Fail")
                    {
                        cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload5.Value);
                        strUpload = strUpload + strResult + ",";
                    }
                }
                else
                {
                    strJs = "alert('File này đã tồn tại');";
                    Page.RegisterClientScriptBlock("File4Js", "<script language='javascript'>" + strJs + "</script>");
                }
            }
            else
            {
                strResult = objUpload.UpLoadFiles(FileUpload1, strduongdannghi, FileUpload5.Value);
                if (strResult != "Fail")
                {
                    cBDuLieuSo.ImportFileToDataBase(strduongdannghi, FileUpload5.Value);
                    strUpload = strUpload + strResult + ",";
                }
            }
        }

        if(strResult.Trim()!="")
        {
            lblUploaded.Text = "Các file đã được tải:" + strUpload.Substring(0, strUpload.Length - 1);
           Page.RegisterClientScriptBlock("Refresh", "<script language='javascript'>opener.location.href='DuLieuSo.aspx?Loc=" + txtthumucupload.Text.Replace("\\","\\\\") + "';</script>");
        }
    }
    protected void btnNhapKhau_Click(object sender, EventArgs e)
    {
        UpLoad();
    }
}
